<?php
class Sessions {
	function Sessions () {
		global $setupdata, $mysqlclass;
		$this->setupdata = $setupdata;
		$this->mysqlclass = $mysqlclass;
	}

	function save_ses(){
		if (!isset($_GET['admin'])) $admin=NULL; else $admin=$_GET['admin'];
		if ($admin==NULL) if (!isset($_POST['admin'])) $admin=NULL; else $admin=$_POST['admin'];
		if (isset($setupdata['modules']['clients']['is']) || ($admin == "1")) {
			$w_sesid = session_id();
			$w_usid_admin = 0; $w_usid_client = 0;
			if ((isset($_SESSION['login_user'])) && (strlen($_SESSION['login_user']) > 0)){
				$w_usid_admin = $_SESSION['login_user'];
			} 
			if ((isset($_SESSION['client_login_id'])) && (strlen($_SESSION['client_login_id']) > 0)) {
				$w_usid_client = $_SESSION['client_login_id'];
			}
	
			$w_ip = $_SERVER['REMOTE_ADDR'];
			$tm = date("YmdHis"); $timeout = 18000;
			
			if (isset($_SESSION['havesess'])) $this->mysqlclass->mysql_my_query("UPDATE `".$this->setupdata['table_prefix']."sessions` SET `userid`=".$w_usid_admin.", `time_last`='".$tm."' WHERE `sesid` = '".$w_sesid."' AND `status`='admin'", __LINE__, __FILE__);
			if (isset($_SESSION['client_havesess'])) $this->mysqlclass->mysql_my_query("UPDATE `".$this->setupdata['table_prefix']."sessions` SET `userid`=".$w_usid_client.", `time_last`='".$tm."' WHERE `sesid` = '".$w_sesid."' AND `status`='client'", __LINE__, __FILE__);
	
			$str == "";
			if ($w_usid_admin < 1) $str .= "(`status`='admin')";
			if ($w_usid_client < 1) if ($str != "") $str = "(".$str." OR (`status`='client'))";
	
			if ($str != "") $this->mysqlclass->mysql_my_query("DELETE FROM `".$this->setupdata['table_prefix']."sessions` where `sesid` = '".$w_sesid."' AND ".$str, __LINE__, __FILE__);
	
			$this->mysqlclass->mysql_my_query("DELETE FROM `".$this->setupdata['table_prefix']."sessions` WHERE ".$tm."-`time_last`>".$timeout, __LINE__, __FILE__);
		}
	}
	
}
?>
